package net.hn.hnms.biz.support.group.service.impl;

import net.hn.hnms.biz.support.group.domain.vo.AbscissdataAlarmListVo;
import net.hn.hnms.biz.support.group.domain.vo.AnchordataAlarmListVo;
import net.hn.hnms.biz.support.group.domain.vo.SupportdataAlarmListVo;
import net.hn.hnms.biz.support.group.service.GroupCJDYService;
import net.hn.hnms.biz.support.service.RoofService;
import net.hn.hnms.sys.common.core.constant.Constants;
import net.hn.hnms.sys.common.core.exception.HuaNengException;
import net.hn.hnms.sys.common.redis.domain.SysOrganizationVo;
import net.hn.hnms.sys.common.redis.utils.RedisUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 集团端冲击地压接口实现类
 */
@Service
public class GroupCJDYServiceImpl implements GroupCJDYService {

    /**
     * 冲击地压服务
     */
    @Resource
    private RoofService roofService;
    @Override
    public List<AbscissdataAlarmListVo> getTodayAbscissdataAlarmList() {
        //获取当前公司的所有煤矿
        SysOrganizationVo sysOrganizationVo = RedisUtils.getCacheObject(Constants.SYS_CODESUB_KEY + 0);
        if (sysOrganizationVo == null) {
            throw new HuaNengException(Constants.FAIL, "无法获集团的子煤矿信息，请检查词典");
        }
        List<AbscissdataAlarmListVo> voList = new ArrayList<>();
        for (SysOrganizationVo organizationVo : sysOrganizationVo.getSubCodeList()) {
            //遍历集团所有公司
            for (SysOrganizationVo vo : organizationVo.getSubCodeList()) {
                //遍历所有煤矿
                List<AbscissdataAlarmListVo> abscissAlarmList = roofService.getAbscissAlarmList(vo.getOrgCode());
                for (AbscissdataAlarmListVo abscissdataAlarmListVo : abscissAlarmList) {
                    //煤矿信息集合
                    voList.add(abscissdataAlarmListVo);
                }
            }

        }
        return voList;
    }

    /**
     * 获取今日锚杆索报警列表
     * @return
     */
    @Override
    public List<AnchordataAlarmListVo> getTodayAnchordataAlarmList() {
        //获取当前公司的所有煤矿
        SysOrganizationVo sysOrganizationVo = RedisUtils.getCacheObject(Constants.SYS_CODESUB_KEY + 0);
        if (sysOrganizationVo == null) {
            throw new HuaNengException(Constants.FAIL, "无法获集团的子煤矿信息，请检查词典");
        }
        List<AnchordataAlarmListVo> voList = new ArrayList<>();
        for (SysOrganizationVo organizationVo : sysOrganizationVo.getSubCodeList()) {
            //遍历集团所有公司
            for (SysOrganizationVo vo : organizationVo.getSubCodeList()) {
                //遍历所有煤矿
                List<AnchordataAlarmListVo> anchordataAlarmList = roofService.getTodayAnchordataAlarmList(vo.getOrgCode());
                for (AnchordataAlarmListVo anchordataAlarmListVo : anchordataAlarmList) {
                    //煤矿信息集合
                    voList.add(anchordataAlarmListVo);
                }
            }

        }
        return voList;
    }

    /**
     * 获取今日支架报警列表
     * @return
     */
    @Override
    public List<SupportdataAlarmListVo> getTodaySupportdataAlarmList() {
        //获取当前公司的所有煤矿
        SysOrganizationVo sysOrganizationVo = RedisUtils.getCacheObject(Constants.SYS_CODESUB_KEY + 0);
        if (sysOrganizationVo == null) {
            throw new HuaNengException(Constants.FAIL, "无法获集团的子煤矿信息，请检查词典");
        }
        List<SupportdataAlarmListVo> voList = new ArrayList<>();
        for (SysOrganizationVo organizationVo : sysOrganizationVo.getSubCodeList()) {
            //遍历集团所有公司
            for (SysOrganizationVo vo : organizationVo.getSubCodeList()) {
                //遍历所有煤矿
                List<SupportdataAlarmListVo> supportdataAlarmListVos = roofService.getTodaySupportdataAlarmList(vo.getOrgCode());
                for (SupportdataAlarmListVo supportdataAlarmListVo : supportdataAlarmListVos) {
                    //煤矿信息集合
                    voList.add(supportdataAlarmListVo);
                }
            }

        }
        return voList;
    }

}
